package com.jt.service;

import com.jt.dao.MenuMapper;
import com.jt.pojo.Menu;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
public class AopMenuServiceImpl implements MenuService{
    @Autowired
    private MenuMapper menuMapper;

    private static final Logger log= LoggerFactory.getLogger(AopMenuServiceImpl.class);

    @Cacheable(value = "menu",key = "#id")
    @Override
    public Menu selectById(Long id) {
        log.info("Get Data From MySQL");
        return menuMapper.selectById(id);
    }

    @CachePut(value = "menu",key = "#menu.id")
    @Override
    public Menu insertMenu(Menu menu) {
        menuMapper.insert(menu);
        return menu;
    }

    @CachePut(value = "menu",key = "#menu.id")
    @Override
    public Menu updateMenu(Menu menu) {
        menuMapper.updateById(menu);
        return menu;
    }
}
